package com.example.swd1.gudong.main.sportrang;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.swd1.gudong.R;
import com.example.swd1.gudong.constant.Constant;

import java.util.List;
import java.util.Map;

/**
 * Created by user on 9/9/16.
 */
public class SquareContentAdapter extends BaseAdapter {
    private List<Map<String,Object>> contents;
    private Context context;

    public SquareContentAdapter(Context context,List<Map<String,Object>> stringMap) {
        this.contents=stringMap;
        this.context = context;
    }

    @Override
    public int getCount() {
        return contents.size();
    }

    @Override
    public Object getItem(int position) {
        return contents.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_square_list, null);
            viewHolder.title= (TextView) convertView.findViewById(R.id.tv_square_title);
            viewHolder.image1 = (ImageView) convertView.findViewById(R.id.iv_square_1);
            viewHolder.image2 = (ImageView) convertView.findViewById(R.id.iv_square_2);
            viewHolder.image3 = (ImageView) convertView.findViewById(R.id.iv_square_3);
            convertView.setTag(viewHolder);
        } else {
            viewHolder= (ViewHolder) convertView.getTag();
        }

        Map<String, Object> content = contents.get(position);
        viewHolder.title.setText((CharSequence) content.get(Constant.SQUARE_KEY_TITLE));
        int[] record = (int[]) content.get(Constant.SQUARE_KEY_IMAGE);
        viewHolder.image1.setImageResource(record[0]);
        viewHolder.image2.setImageResource(record[1]);
        viewHolder.image3.setImageResource(record[2]);
        return convertView;
    }

    private class ViewHolder {
        ImageView image1;
        ImageView image2;
        ImageView image3;
        TextView title;
    }
}
